package es.us.lsi.aws.api.externalservices;

import es.us.lsi.aws.api.model.FacebookSocialAccount;
import facebook4j.Facebook;
import facebook4j.FacebookException;
import facebook4j.FacebookFactory;

import facebook4j.auth.AccessToken;

public class FacebookHelper implements ISocialNetwork {

	FacebookSocialAccount acc;
	Facebook facebook;

	public FacebookHelper(FacebookSocialAccount acc) {
		this.acc = acc;
	}

	@Override
	public int post(String message) {

		Facebook facebook = FacebookFactory.getSingleton();

		facebook.setOAuthAppId(OAuthCredentials.facebookCK,
				OAuthCredentials.facebookCS);
		facebook.setOAuthPermissions("");
		facebook.setOAuthAccessToken(new AccessToken("", null));

		try {
			facebook.postStatusMessage(message);

		} catch (FacebookException e) {
			// TODO Auto-generated catch block
			System.err
					.println("Something went wrong trying to post an update in twitter..."
							+ e.getMessage());
			e.printStackTrace();
			return -1;
		}
		return 1;
	}

	@Override
	public String startOAuthProcess() {
		Facebook facebook = new FacebookFactory().getInstance();
		this.facebook = facebook;
		return facebook
				.getOAuthAuthorizationURL("http://mybufferapp.appspot.com/1/accounts/callbackurl/twitter");

	}

	public Facebook getFacebook() {
		return this.facebook;
	}

}
